1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gobject.Binding; 26 27 private import glib.Str; 28 private import glib.c.functions; 29 private import gobject.ObjectG; 30 private import gobject.c.functions; 31 public import gobject.c.types; 32 33 34 /** 35 * #GBinding is the representation of a binding between a property on a 36 * #GObject instance (or source) and another property on another #GObject 37 * instance (or target). 38 * 39 * Whenever the source property changes, the same value is applied to the 40 * target property; for instance, the following binding: 41 * 42 * |[<!-- language="C" --> 43 * g_object_bind_property (object1, "property-a", 44 * object2, "property-b", 45 * G_BINDING_DEFAULT); 46 * ]| 47 * 48 * will cause the property named "property-b" of @object2 to be updated 49 * every time g_object_set() or the specific accessor changes the value of 50 * the property "property-a" of @object1. 51 * 52 * It is possible to create a bidirectional binding between two properties 53 * of two #GObject instances, so that if either property changes, the 54 * other is updated as well, for instance: 55 * 56 * |[<!-- language="C" --> 57 * g_object_bind_property (object1, "property-a", 58 * object2, "property-b", 59 * G_BINDING_BIDIRECTIONAL); 60 * ]| 61 * 62 * will keep the two properties in sync. 63 * 64 * It is also possible to set a custom transformation function (in both 65 * directions, in case of a bidirectional binding) to apply a custom 66 * transformation from the source value to the target value before 67 * applying it; for instance, the following binding: 68 * 69 * |[<!-- language="C" --> 70 * g_object_bind_property_full (adjustment1, "value", 71 * adjustment2, "value", 72 * G_BINDING_BIDIRECTIONAL, 73 * celsius_to_fahrenheit, 74 * fahrenheit_to_celsius, 75 * NULL, NULL); 76 * ]| 77 * 78 * will keep the "value" property of the two adjustments in sync; the 79 * @celsius_to_fahrenheit function will be called whenever the "value" 80 * property of @adjustment1 changes and will transform the current value 81 * of the property before applying it to the "value" property of @adjustment2. 82 * 83 * Vice versa, the @fahrenheit_to_celsius function will be called whenever 84 * the "value" property of @adjustment2 changes, and will transform the 85 * current value of the property before applying it to the "value" property 86 * of @adjustment1. 87 * 88 * Note that #GBinding does not resolve cycles by itself; a cycle like 89 * 90 * |[ 91 * object1:propertyA -> object2:propertyB 92 * object2:propertyB -> object3:propertyC 93 * object3:propertyC -> object1:propertyA 94 * ]| 95 * 96 * might lead to an infinite loop. The loop, in this particular case, 97 * can be avoided if the objects emit the #GObject::notify signal only 98 * if the value has effectively been changed. A binding is implemented 99 * using the #GObject::notify signal, so it is susceptible to all the 100 * various ways of blocking a signal emission, like g_signal_stop_emission() 101 * or g_signal_handler_block(). 102 * 103 * A binding will be severed, and the resources it allocates freed, whenever 104 * either one of the #GObject instances it refers to are finalized, or when 105 * the #GBinding instance loses its last reference. 106 * 107 * Bindings for languages with garbage collection can use 108 * g_binding_unbind() to explicitly release a binding between the source 109 * and target properties, instead of relying on the last reference on the 110 * binding, source, and target instances to drop. 111 * 112 * #GBinding is available since GObject 2.26 113 * 114 * Since: 2.26 115 */ 116 public class Binding : ObjectG 117 { 118 /** the main Gtk struct */ 119 protected GBinding* gBinding; 120 121 /** Get the main Gtk struct */ 122 public GBinding* getBindingStruct(bool transferOwnership = false) 123 { 124 if (transferOwnership) 125 ownedRef = false; 126 return gBinding; 127 } 128 129 /** the main Gtk struct as a void* */ 130 protected override void* getStruct() 131 { 132 return cast(void*)gBinding; 133 } 134 135 /** 136 * Sets our main struct and passes it to the parent class. 137 */ 138 public this (GBinding* gBinding, bool ownedRef = false) 139 { 140 this.gBinding = gBinding; 141 super(cast(GObject*)gBinding, ownedRef); 142 } 143 144 145 /** */ 146 public static GType getType() 147 { 148 return g_binding_get_type(); 149 } 150 151 /** 152 * Retrieves the #GObject instance used as the source of the binding. 153 * 154 * A #GBinding can outlive the source #GObject as the binding does not hold a 155 * strong reference to the source. If the source is destroyed before the 156 * binding then this function will return %NULL. 157 * 158 * Returns: the source #GObject, or %NULL if the 159 * source does not exist any more. 160 * 161 * Since: 2.68 162 */ 163 public ObjectG dupSource() 164 { 165 auto __p = g_binding_dup_source(gBinding); 166 167 if(__p is null) 168 { 169 return null; 170 } 171 172 return ObjectG.getDObject!(ObjectG)(cast(GObject*) __p, true); 173 } 174 175 /** 176 * Retrieves the #GObject instance used as the target of the binding. 177 * 178 * A #GBinding can outlive the target #GObject as the binding does not hold a 179 * strong reference to the target. If the target is destroyed before the 180 * binding then this function will return %NULL. 181 * 182 * Returns: the target #GObject, or %NULL if the 183 * target does not exist any more. 184 * 185 * Since: 2.68 186 */ 187 public ObjectG dupTarget() 188 { 189 auto __p = g_binding_dup_target(gBinding); 190 191 if(__p is null) 192 { 193 return null; 194 } 195 196 return ObjectG.getDObject!(ObjectG)(cast(GObject*) __p, true); 197 } 198 199 /** 200 * Retrieves the flags passed when constructing the #GBinding. 201 * 202 * Returns: the #GBindingFlags used by the #GBinding 203 * 204 * Since: 2.26 205 */ 206 public GBindingFlags getFlags() 207 { 208 return g_binding_get_flags(gBinding); 209 } 210 211 /** 212 * Retrieves the #GObject instance used as the source of the binding. 213 * 214 * A #GBinding can outlive the source #GObject as the binding does not hold a 215 * strong reference to the source. If the source is destroyed before the 216 * binding then this function will return %NULL. 217 * 218 * Use g_binding_dup_source() if the source or binding are used from different 219 * threads as otherwise the pointer returned from this function might become 220 * invalid if the source is finalized from another thread in the meantime. 221 * 222 * Deprecated: Use g_binding_dup_source() for a safer version of this 223 * function. 224 * 225 * Returns: the source #GObject, or %NULL if the 226 * source does not exist any more. 227 * 228 * Since: 2.26 229 */ 230 public ObjectG getSource() 231 { 232 auto __p = g_binding_get_source(gBinding); 233 234 if(__p is null) 235 { 236 return null; 237 } 238 239 return ObjectG.getDObject!(ObjectG)(cast(GObject*) __p); 240 } 241 242 /** 243 * Retrieves the name of the property of #GBinding:source used as the source 244 * of the binding. 245 * 246 * Returns: the name of the source property 247 * 248 * Since: 2.26 249 */ 250 public string getSourceProperty() 251 { 252 return Str.toString(g_binding_get_source_property(gBinding)); 253 } 254 255 /** 256 * Retrieves the #GObject instance used as the target of the binding. 257 * 258 * A #GBinding can outlive the target #GObject as the binding does not hold a 259 * strong reference to the target. If the target is destroyed before the 260 * binding then this function will return %NULL. 261 * 262 * Use g_binding_dup_target() if the target or binding are used from different 263 * threads as otherwise the pointer returned from this function might become 264 * invalid if the target is finalized from another thread in the meantime. 265 * 266 * Deprecated: Use g_binding_dup_target() for a safer version of this 267 * function. 268 * 269 * Returns: the target #GObject, or %NULL if the 270 * target does not exist any more. 271 * 272 * Since: 2.26 273 */ 274 public ObjectG getTarget() 275 { 276 auto __p = g_binding_get_target(gBinding); 277 278 if(__p is null) 279 { 280 return null; 281 } 282 283 return ObjectG.getDObject!(ObjectG)(cast(GObject*) __p); 284 } 285 286 /** 287 * Retrieves the name of the property of #GBinding:target used as the target 288 * of the binding. 289 * 290 * Returns: the name of the target property 291 * 292 * Since: 2.26 293 */ 294 public string getTargetProperty() 295 { 296 return Str.toString(g_binding_get_target_property(gBinding)); 297 } 298 299 /** 300 * Explicitly releases the binding between the source and the target 301 * property expressed by @binding. 302 * 303 * This function will release the reference that is being held on 304 * the @binding instance if the binding is still bound; if you want to hold on 305 * to the #GBinding instance after calling g_binding_unbind(), you will need 306 * to hold a reference to it. 307 * 308 * Note however that this function does not take ownership of @binding, it 309 * only unrefs the reference that was initially created by 310 * g_object_bind_property() and is owned by the binding. 311 * 312 * Since: 2.38 313 */ 314 public void unbind() 315 { 316 g_binding_unbind(gBinding); 317 } 318 }